package com.kadron.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.kadron.base.KVBase;

@Entity
@Table(name = "k_user_discount")
public class UserDiscount extends KVBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7118898018111012499L;
	
	private User user;
	private Date start;
	private Date end;
	
	public UserDiscount() {
		super();
	}
	
	public UserDiscount(User user, Date start, Date end) {
		this();
		this.user = user;
		this.start = start;
		this.end = end;
	}

	@ManyToOne(targetEntity = User.class)
	@JoinColumn(name = "user_id", nullable = false, updatable = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "start")
	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "end")
	public Date getEnd() {
		return end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + (int) (getId() ^ (getId() >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserDiscount other = (UserDiscount) obj;
		if (getId() != other.getId())
			return false;
		return true;
	}
}